package br.edu.ufcg.greengrid.model.machine.state;

import br.edu.ufcg.greengrid.model.job.Job;
import br.edu.ufcg.greengrid.model.machine.Machine;

public class IdleMachineState extends AbstractMachineState {

	@Override
	public MSEnum getType() {
		
		return MSEnum.IDLE;
	}
	
	public void run(Machine m, Job nJob) {
		
		m.setJob(nJob);
		m.changeState(MSEnum.GRID, this.countdown);//XXX The "changeState" method should be called only inside "changeStateIfNeeded" method. What about this?
	}
	
	@Override
	public void changeStateIfNeeded(Machine m) {
		MSEnum newStateType = null;
		long countdown = 0L;
		
		if(isCountdownZero()){
			newStateType = MSEnum.USER;
			countdown = 0L;
		}
		
		if(newStateType != null){
			m.changeState(newStateType, countdown);
		}
	}
	
	
}
